package org.NooLab.texx.plugg.algo.intf;

import java.util.ArrayList;

import org.NooLab.texx.plugg.DataDescription;




abstract public class AlgoAssignatorAbstract implements AlgoAssignatorIntf{

	private static final long serialVersionUID = 731065532642808706L;

	int typeInfo = AlgorithmIntf._ALGOTYPE_ASSIGNATOR ;
	 
	// ....................................................

	ArrayList<ArrayList<?>> assignates ;
	protected ArrayList<String> headerColumns ;  
	protected ArrayList<Double> values ;
	protected String columnPrefix = "";
	
	protected AlgoSourceDescription sourceDescription; 
	
	protected int rangeViolationHandlingMode = AlgorithmIntf._ALGO_RANGEVIOLATION_AUTOCORRECT ;
	protected int rangeViolationCounter=0;
	
	protected boolean hasParameters = false; // will be true in case of algorithms like NumValEnum
	
	protected AlgorithmParameters parameters ; 
	
	protected String autoDescription = "" ;

	protected int outputColumnsCount = 0;

	protected TextObject textObj;

	protected String text = "";
	
	// ------------------------------------------------------------------------
	public AlgoAssignatorAbstract(){
		parameters = new AlgorithmParameters( this) ;
		
		assignates = new ArrayList<ArrayList<?>> ();
		headerColumns = new ArrayList<String>();  
		values = new ArrayList<Double>();
		
		assignates.add(headerColumns);
		assignates.add(values) ;
	}
	

	@Override
	public void setTextValue( TextObject textObj){
		
		this.textObj = textObj ;
		text = textObj.getText();
	}

	
	abstract public int calculate() throws Exception ;
	
	@Override
	public ArrayList<ArrayList<?>> getAssignates() {
	
		return assignates;
	}


	// ------------------------------------------------------------------------
	 
		
	@Override
	public void clearText() {
		;
	}
	@Override
	public int getType() {
		return typeInfo;
	}
	

	@Override
	public void setColumnPrefix(String prefix) {
		columnPrefix = prefix;
	}
	
	public String getColumnPrefix() {
		return columnPrefix;
	}

	
	abstract public String getDescription() ;
	
	
	/**
	 * @return the hasParameters
	 */
	public boolean hasParameters() {
		return hasParameters;
	}


	@Override
	public AlgorithmParameters getParameters() {
		return parameters;
	}
	
 
	
	
	@Override
	public void setParameters(AlgorithmParameters algorithmparams)  throws Exception{
		
		if (parametersNullCheck(algorithmparams)==false) return;
		basicParametersAssimilation(algorithmparams) ;
		
		Class clzz = getClass().getMethod("setParameters").getDeclaringClass();
		if (clzz != this.getClass()){
			// of which interface?   C:\Programs\dev\eclipse\xlibs\reflection
			Class[] intfaces = clzz.getInterfaces() ;
			
		}

	}

	protected boolean parametersNullCheck(AlgorithmParameters algorithmparams){
		boolean rB=true;
		
		if (algorithmparams==null){
			rB=false;
		}
		if ((algorithmparams.items==null) || (algorithmparams.items.size()==0)){
			rB=false;
		}
		return rB;
	}

	protected void basicParametersAssimilation(AlgorithmParameters algorithmParams){
		
		AlgorithmParametersHelper paramsHelper = new AlgorithmParametersHelper ();
		
		parameters = paramsHelper.assimilate(this, algorithmParams);
	}
	
	protected void basicParametersAssimilation( ArrayList<Object> params ){
		
		AlgorithmParametersHelper paramsHelper = new AlgorithmParametersHelper ();
		
		parameters = paramsHelper.assimilateOpenObjectList(this, params);
		
	}
	 
	
	
	public String[] showAvailableParameters() {
		String[] paramsDescription = new String[0];
		return paramsDescription;
	}	
	

	public int getRangeViolationCounter() {
		return rangeViolationCounter;
	}

	public void setRangeViolationCounter(int rvCounter) {
		this.rangeViolationCounter = rvCounter;
	}


	public TextObject getTextObj() {
		return textObj;
	}


	public void setTextObj(TextObject textObj) {
		this.textObj = textObj;
	}


	public String getText() {
		return text;
	}


	public void setText(String text) {
		this.text = text;
	}
	
}
